package online.westonline.com.westonline.utils;

import com.easy.west.westclient.api.constacts.bean.PersonBean;
import com.easy.west.westclient.api.department.bean.AllDepartMentBean;
import com.easy.west.westclient.api.login.bean.User;
import com.easy.west.westclient.api.message.bean.MessageBean;
import com.orhanobut.hawk.Hawk;

import java.util.ArrayList;
import java.util.List;

import online.westonline.com.westonline.MyApplication;
import online.westonline.com.westonline.R;
import online.westonline.com.westonline.entry.MeetFormBean;
import online.westonline.com.westonline.entry.WorkItem;

/**
 * 储存应用的相关配置
 * Created by xiatao on 2018/6/6.
 */

public class CacheUtils
{
    private static volatile CacheUtils instance;
    private AllDepartMentBean allDepatMent;

    private CacheUtils()
    {

    }

    public static CacheUtils getInstance() {
        if (instance==null)
        {
            synchronized (CacheUtils.class)
            {
                if (instance==null)
                {
                    instance = new CacheUtils();
                }


            }
        }
        return instance;
    }

    /**
     * 是否默认识别
     * @param flag
     */
    public void setIsAutoLink(boolean flag)
    {
        Hawk.put("link",flag);
    }

    /**
     * 获取默认识别标示
     * @return
     */
    public boolean getIsAutoLink()
    {
     return  Hawk.get("link",false);
    }
    /**
     *更新未选择的工作功能
     * @param list
     *
    public void setNotAddWorkItem(List<WorkItem> list)
    {
        Hawk.put("not_add_work",list);
    }

    /**
     * 获取未加入的工作功能
     * @return
     *
    public List<WorkItem> getNotAddWorkItem()
    {
        return Hawk.get("not_add_work",null);
    }
    /**
     * 工作空间更新后的bean(适用于主空间)
     * @param list
     */
    public void setWorkItemPosition(List<WorkItem> list)
    {
        Hawk.put("list_work",list);

    }
    /**
     * 更新workitem
     * 原因是因为在主界面或获取的...好吧没必要
     *
    public void updateWorkItem(String title)
    {
        List<>
    }
    */

    /**
     * 获取工作空间标题
     * @return
     */
    public List<WorkItem> getWorkItem()
    {
        return Hawk.get("list_work",null);

    }

    /**
     * 初始化工作模块
     */
    public List<WorkItem> initworkmode() {
        WorkItem contacts = new WorkItem();
        contacts.setTitle("通讯录");
        contacts.setWid(0);
        contacts.setIcon_id(R.drawable.phone);
        contacts.setDescrible("找到联系人");
        WorkItem meetting = new WorkItem();
        meetting.setTitle("会议室预定");
        meetting.setIcon_id(R.drawable.conference);
        meetting.setDescrible("无纸办公室");
        meetting.setWid(1);
        WorkItem importantnotice = new WorkItem();
        importantnotice.setTitle("重要通知");
        importantnotice.setIcon_id(R.drawable.message);
        importantnotice.setDescrible("第一手通知");
        importantnotice.setWid(2);
        WorkItem work_together = new WorkItem();
        work_together.setTitle("一起上班");
        work_together.setIcon_id(R.drawable.work);
        work_together.setDescrible("寻找小伙伴");
        work_together.setWid(3);
        WorkItem table_bussines = new WorkItem();
        table_bussines.setTitle("抄表业务");
        table_bussines.setIcon_id(R.drawable.reading);
        table_bussines.setDescrible("电子记录");
        table_bussines.setWid(4);
        WorkItem work_plan = new WorkItem();
        work_plan.setTitle("工作计划");
        work_plan.setIcon_id(R.drawable.plan);
        work_plan.setDescrible("安排日程");
        work_plan.setWid(5);
        WorkItem work_node = new WorkItem();
        work_node.setIcon_id(R.drawable.note);
        work_node.setDescrible("备忘录");
        work_node.setTitle("工作便签");
        work_node.setWid(6);
        WorkItem work = new WorkItem();
        work.setDescrible("高效率");
        work.setTitle("工作无忧");
        work.setWid(7);
        work.setIcon_id(R.drawable.free);
        List<WorkItem> arr = new ArrayList<>();
        arr.add(contacts);
        arr.add(meetting);
        arr.add(importantnotice);
        arr.add(work_together);
        arr.add(table_bussines);
        arr.add(work_plan);
        arr.add(work_node);
        arr.add(work);
        return arr;
    }

    /**
     * 记住密码
     * @param flag
     */
    public  void remberPasswordCheck(boolean flag)
    {
        Hawk.put("check_password",flag);
        if (!flag)
        {
            //清除账号密码
            //清除用户实体
            Hawk.put("username",null);
            Hawk.put("password",null);
        }
    }

    /**
     * 获取密码选中状态
     * @return
     */
    public  boolean getPasswordCheckValue()
    {
       return Hawk.get("check_password",false);
    }

    /**
     * 记住账号名称和密码
     * @param username
     * @param password
     */
    public  void remberUserAndPassword(String username,String password)
    {
        if (getPasswordCheckValue())
        {
            Hawk.put("username",username);
            Hawk.put("password",password);
        }
        else
        {
            ToastUtils.showToast("前置行为未完成");
        }
    }
    /**
     * 记住账号名称和密码
     * @param username
     * @param password
     */
    public  void remberUserAndPasswordByMisu(String username,String password)
    {
        if (getPasswordCheckValue())
        {
            Hawk.put("username_misu",username);
            Hawk.put("password_misu",password);
        }
        else
        {
            ToastUtils.showToast("前置行为未完成");
        }
    }
    /**
     * 获取用户名
     * @return
     */
    public String getUserNameByMisu()
    {
        return Hawk.get("username_misu",null);
    }

    /**
     * 设置操作模式
     * @param flag
     */
    public void setMode(boolean flag)
    {
        Hawk.put("misu",flag);
    }

    public boolean getMode()
    {
        return Hawk.get("misu",false);
    }

    /**
     * 获取密码
     * @return
     */
    public String passwordByMisu()
    {
        return Hawk.get("password_misu",null);
    }

    /**
     * 存入秘书
     * @param miSu
     *
    public void saveMisu(UserMiSu miSu)
    {
        Hawk.put("user_misu",miSu);
    }
*/
    /**
     * 获取秘书
     * @return
     *
    public UserMiSu getMisu()
    {
     return Hawk.get("user_misu");
    }
    */
    /**
     * 获取用户名
     * @return
     */
    public String getUserName()
    {
       return Hawk.get("username",null);
    }

    /**
     * 获取密码
     * @return
     */
    public String password()
    {
        return Hawk.get("password",null);
    }

    /**
     * 闪屏页面状态(引导页)
     * @param flag
     */
    public void setSplashEnable(boolean flag)
    {
        Hawk.put("guide",flag);
        //闪屏页面
    }

    /**
     * 获取引导页状态
     * @return true未看该页面
     */
    public boolean getSplashEnable()
    {
        return Hawk.get("guide",true);
    }

    /**
     * 存储user
     * @param user
     */
    public void saveUser(User user)
    {
        Hawk.put("user",user);
    }

    public void removeuser()
    {
        Hawk.put("user",null);
    }
    /**
     * 获取
     * @return
     */
    public User getUser()
    {
        return Hawk.get("user");
    }

    /**
     * 悬浮窗tag
     */
    public String getFloatTag()
    {
        Hawk.put("tag","window");
        return Hawk.get("tag",null);
    }

    /**
     * 悬浮窗状态
     */
    public void saveFloatState(boolean flag)
    {
        Hawk.put("float",flag);
    }

    public boolean getFloatState()
    {
        return Hawk.get("float",false);
    }

    /**
     * 保存用户头像
     */
    public void saveUserAvatarPath(String path) {
        Hawk.put("avator",path);
    }

    public String getUserAvatarPath()
    {
        return Hawk.get("avator",null);
    }
    /**
     * 保存当前用户用于聊天的手机号
     * @param userName
     */
    public void saveUserPhone(String userName) {
        Hawk.put("chat_phone",userName);
    }

    public String getUsetPhone()
    {
        return Hawk.get("chat_phone",null);
    }

    /**
     * 存入会话数量
     * @param cancelTopSize
     */
    public void setCancelTopSize(int cancelTopSize) {
       Hawk.put("top_size",cancelTopSize);
    }

    /**
     * 获取会话数量
     * @return
     */
    public int getCancelTopSize() {
        return Hawk.get("top_size",0);
    }

    /***
     * 保存会议表单
     * @param mrid
     * @param meetFormBean
     */
    public void saveMeetFormBean(int mrid, MeetFormBean meetFormBean) {
        Hawk.put(String.valueOf(mrid),meetFormBean);
    }

    public MeetFormBean getMeetFormBean(int mrid)
    {
       return Hawk.get(String.valueOf(mrid),null);
    }

    public void clearForm(int mrid) {
        Hawk.put(String.valueOf(mrid),null);
    }

    /**
     * 保存会议模板
     * @param classname
     * @param meetFormBean
     */
    public void saveMeetFormGaide(String classname,MeetFormBean meetFormBean)
    {
        Hawk.put(classname,meetFormBean);
    }
    /**
     * 查找模板会议室表单
     * @return
     */
    public MeetFormBean getMeetFormBeanGaide(String classname) {
      return   Hawk.get(classname,null);
    }

    /**
     * 保存所有的department列表
     * @param dataBeanList
     */
    public void saveDepartMent(List<AllDepartMentBean.DataBean> dataBeanList) {
        Hawk.put(MyApplication.getContext().getString(R.string.app_name),dataBeanList);
    }

    /**
     * 获取
     * @return
     */
    public List<AllDepartMentBean.DataBean> getAllDepatMent() {
        return Hawk.get(MyApplication.getContext().getString(R.string.app_name),null);
    }

    /**
     * 保存联系人列表
     * @param did
     * @param data
     */
    public void saveDepartMentConstacts(int did, List<PersonBean> data) {
        Hawk.put(String.valueOf(did),data);
    }

    public List<PersonBean> getDepartMentConstacts(String did) {
        return Hawk.get(String.valueOf(did),null);
    }

    /***
     * 保存用户的消息列表
     * @param access_token
     * @param messageBeanList
     */
    public void saveMessageList(String access_token, List<MessageBean> messageBeanList) {
        Hawk.put(access_token,messageBeanList);
    }

    /**
     * 获取消息列表
     * @param access_token
     * @return
     */
    public List<MessageBean> getMessageList(String access_token)
    {
      return Hawk.get(access_token,null);
    }
}
